﻿; (function (window, undefined, $) {
    $(document).ready(function () {
        var gridopt = {
            url: options.listUrl,
            colModel: [
                    { display: '编号', name: 'Id', width: "5%", sortable: true, hide: true, align: 'left', iskey: true },
                    { display: 'Status', name: 'Status', sortable: true, hide: true, align: 'left', iskey: true },
                    //{ display: '基金编号', name: 'FundID', width: "15%", sortable: true, hide: false, align: 'left', iskey: true },
                    { display: '基金', name: 'PrivatelyFundName', width: "15%", sortable: true, hide: false, align: 'left', iskey: true },
                    { display: '预约人姓名', name: 'ReserveName', width: "5%", sortable: true, hide: false, align: 'left', iskey: true },
                    { display: '预留电话', name: 'MobileNumber', width: "15%", sortable: false, align: 'left' },
                    { display: '预留时间', name: 'ReserveDate', width: "15%", sortable: false, align: 'left' },
                    { display: '操作', name: 'Id', width: "15%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "ReserveDate",
            sortorder: "DESC",
            title: false,
            rp: 10,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        function processOp(value, cell) {
            var ops = [];
            if (cell[1] == 0) {
                ops.push("&nbsp;<a title='受理' href='javascript:;'  onclick=\"util.Accept('", value, "')\"><i class='fa fa-edit' ></i>受理</a>");
                ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");

            } else if (cell[1] == 1) {
                ops.push("&nbsp;&nbsp;已受理");
                ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            }
            //ops.push("&nbsp;<a title='审核' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>审核</a>");
            //ops.push("&nbsp;<a title='编辑' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>编辑</a>");
          
            return ops.join("");
        }

        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });
        $("#btnAdd").click(function (e) {
            var url = options.editUrl;
            window.location.href = url;
        });

        util.Edit = function (Id) {
            var url = options.editUrl + "/" + Id;
            location.href = url;
        };
        util.Accept = function (Id) {
            $.post(options.AcceptUrl + "/" + Id, { Id: Id },
                 function (res) {
                     if (res.status > 0) {
                         alert(res.message);
                         xjgrid.Reload(this);
                     }
                     else {
                         alert(res.Message);
                     }
                 },
                 "json"
           );
        };
        util.Delete = function (Id, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + Id, { Id: Id },
                  function (res) {
                      if (res.status > 0) {
                          alert(res.message);
                          xjgrid.Reload(this);
                      }
                      else {
                          alert(res.Message);
                      }
                  },
                  "json"
            );
        };
    });

})(window, undefined, jQuery);